var app = getApp();
var util = require('../../../../utils/util.js');
var guanPage;  //存放上一个页面的信息
var rightDatas; //存放上一个页面的列表
var end; //上一个页面当前页有几个商品
var cur_page_index;  //当前页的第一个订单索引
var del_ck;  //是否点击了删除
Page({

  /**
   * 页面的初始数据
   */
  data: {
    selectdanwei: false, //选择单位弹窗
    showModalStatus: false, //底部分类弹窗
    selectdingjia: true, //规格定价模式下拉框
    selectshop: false, //编辑产品弹窗
    selectguige: false, //规格定价模式下拉框
    xselectdingjia: true, //定价模式下拉框
    setcover: '', //上传图片地址
    value: [0, 0], //底部弹窗初始值
    is_show_detail: '',//是否显示详情
    specs:'',//显示规格
    quality_time:'',//保质期
    specs_detail:'',//规格详情
    isname:false, //修改名称
    isalias:false,  //别名弹窗
    isdingjia:false,  //修改定价模式
    iscost:false,   //设置成本价
    islevel:false,   //设置
    isjia:false, //上架-下架
    issuper:false,  //选择供应商
    ishisprice:false, //查看历史价
    z_trade_name:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.coll!=1){
      del_ck=false;
      const pages = getCurrentPages();    //获取当前页面信息栈
      guanPage = pages[pages.length - 2]; //获取上一个页面信息 
      rightDatas = guanPage.data.rightDatas;   //获取上一个页面的列表
      cur_page_index=guanPage.data.cur_page_index;   //当前页的第一个订单索引
      end=guanPage.length-cur_page_index;   //上一个页面当前页有几个订单
    };
    this.setData({
      good_dir_set:app.globalData.loginInfo.good_dir_set,
      id:app.globalData.loginInfo.id,
      raplace_h:0.8*wx.getSystemInfoSync().windowHeight,
      unit_height:0.64* wx.getSystemInfoSync().windowHeight,
      k_index:options.k_index?options.k_index:-1,
      nav:options.nav?options.nav:"",
      coll:options.coll?options.coll:''
    });
    this.uplist();
    this.startcatelist();
  },
  uplist: function() {
    var that = this;
    app.AppHttp('api/Supplier/editGoodPage', {
      id: app.globalData.goodid
    }, function(res) {
      console.log(JSON.stringify(res.data));
      that.setData({
        goodid: res.data.id,
        trade_name: res.data.trade_name,
        status:res.data.status,
        one_class: res.data.one_class,
        two_class: res.data.two_class,
        cover: res.data.cover,
        trade_alias: res.data.trade_alias,
        one_class_name: res.data.one_class_name,
        two_class_name: res.data.two_class_name,
        price_type: res.data.price_type,
        is_open:res.data.is_open,
        true_price: res.data.true_price,
        unit_name: res.data.unit_name,
        unitindex: res.data.unit,
        specs_list: res.data.specs_list,
        priceGoodList:res.data.priceGoodList,
        levelList:res.data.levelList,
        b_supplier_id:res.data.b_supplier_id,
        b_supplier_name:res.data.b_supplier_name,
        is_show_detail: res.data.is_show_detail,
        true_price:res.data.true_price, //成本价
        // quality_time: res.data.quality_time,
        is_basic_search:res.data.is_basic_search,
        str: res.data.abbreviation,
        specs_detail: res.data.specs
      })
      if (res.data.quality_time!=0){
        that.setData({
          quality_time: res.data.quality_time_name
        })
      };
    });
  },
  // 保存
  baochu: function() {
    var that = this;
    //验证第一个字符串
    var regNumber = /[A-Za-z]/;
    var typestr = typeof this.data.str;
    if (typestr == "string") {
      var str = this.data.str;
    }else {
      var str = this.data.str.join('');
    }
    var str1 = ''
    for (var i in str) {
      if (regNumber.test(str[i])) {
        str1 += str[i];
      }
    }
    let shop_trade_name = that.data.z_trade_name?that.data.z_trade_name:that.data.trade_name;
    app.AppHttp('api/Supplier/editGoodDo', {
      id: that.data.goodid,
      trade_name: shop_trade_name.trim(),
      one_class: that.data.one_class,
      two_class: that.data.two_class,
      cover: that.data.setcover,
      trade_alias: that.data.trade_alias.trim(),
      unit: that.data.unitindex,
      price_type: that.data.price_type,
      true_price: that.data.true_price,
      abbreviation: str1.trim(),
      remark: '',
      specs: that.data.specs_detail,
      quality_time: that.data.quality_time,
      is_show_detail: that.data.is_show_detail
    }, function(res) {
      console.log(JSON.stringify(res.data));
      app.globalData.shopname = that.data.trade_name;
      if (res.data.status == 1) {
        wx.showToast({
          title: res.data.msg
        });
        if(that.data.isname==true){
          that.setData({
            isname:false,
            trade_name:that.data.z_trade_name
          });
        };
        if(that.data.selectshop==true){
          that.setData({
            selectshop:false,
            unit_name:that.data.specs_unit_name
          });
        };
        if(that.data.coll!=1){
          if(that.data.nav=='sear' || guanPage.data.one_id==that.data.one_class && guanPage.data.two_id==that.data.two_class){
            if(that.data.selectshop==true){
              guanPage.setData({
                isguige:[]
              });
            };
            if(that.data.isname==true){
              guanPage.setData({
                ["rightDatas[" + that.data.k_index + "].trade_name"]:that.data.z_trade_name
              });
            };
            if(that.data.setcover!=''){
              guanPage.setData({
                ["rightDatas[" + that.data.k_index + "].cover"]:that.data.setcover
              });
            };
            if(that.data.unitindex){
              guanPage.setData({
                ["rightDatas[" + that.data.k_index + "].unit_name"]:that.data.unit_name
              });
            };        
          };
        }else{
          app.globalData.shop_manage = 1;
        };         
      }
    })
  },
  // 更新所属分类
  startcatelist: function() {
    var that = this;
    app.AppHttp('api/Supplier/CateList', {
      id: that.data.id,
      e_type:'client'
    }, function(res) {
      console.log(JSON.stringify(res.data));
      if (res.data.two_class_list.length == 0) {
        that.setData({
          one_class_list: res.data.one_class_list,
          one_class_zhname: res.data.one_class_list[0].private_class_name,
          one_class_zh: res.data.one_class_list[0].private_one_class,
          two_class_list: [''],
          notwo: 1
        })
        return;
      }
      that.setData({
        one_class_list: res.data.one_class_list,
        two_class_list: res.data.two_class_list,
        one_class_zhname: res.data.one_class_list[0].private_class_name,
        two_class_zhname: res.data.two_class_list[0].private_class_name,
        one_class_zh: res.data.one_class_list[0].private_one_class,
        two_class_zh: res.data.two_class_list[0].private_one_class,
        value: [0, 0]
      })
    })
  },
  // 上传图片
  changeimg: function() {
    if(this.data.is_basic_search==1){
      var that = this;
      wx.navigateTo({
        url: '../../../cropper/cropper?imgx=3'
      });
    }  
  },
  // 修改名称
  change_name:function(){
    this.setData({
      isname:true,
      z_trade_name:this.data.trade_name
    });
  },
  // 关闭名称弹窗
  name_cancel:function(){
    this.setData({
      isname:false
    });
  },
  // 输入名称
  name_input:function(e){
    this.setData({
      z_trade_name:e.detail.value
    });
  },
  // 打开修改别名弹窗
  change_alias:function(){
    this.setData({
      isalias:true,
      z_trade_alias:this.data.trade_alias
    });
  },
  // 输入别名
  alias_input:function(e){
    this.setData({
      z_trade_alias:e.detail.value
    });
  },
  // 关闭别名弹窗
  alias_cancel:function(){
    this.setData({
      isalias:false
    });
  },
  // 确定别名
  alias_conf:function(){
    var that = this;
    app.AppHttp('api/Goods/setTradeAlias', {
      id: that.data.goodid,
      trade_alias:that.data.z_trade_alias
    }, function(res) {
      console.log(JSON.stringify(res.data))
      that.setData({
        isalias:false,
        trade_alias:that.data.z_trade_alias
      });
      if(that.data.coll!=1){
        if(that.data.nav=='sear' || guanPage.data.one_id==that.data.one_class && guanPage.data.two_id==that.data.two_class){
          guanPage.setData({
            ["rightDatas[" + that.data.k_index + "].trade_alias"]:that.data.z_trade_alias
          });
        }; 
      }else{
        app.globalData.shop_manage = 1;
      };     
    }); 
  },
  // 修改定价模式
  setdingjia:function(){
    this.setData({
      isdingjia:true
    });
  },
  // 关闭定价模式
  cancel_dingjia:function(){
    this.setData({
      isdingjia:false
    });
  },
  // 确定定价模式
  dingjia_conf:function(e){
    var that = this;
    app.AppHttp('api/Goods/setPriceType', {
      id: that.data.goodid,
      price_type:e.currentTarget.dataset.price_type
    }, function(res) {
      console.log(JSON.stringify(res.data));
      that.uplist();
      that.setData({
        isdingjia:false,
        price_type:e.currentTarget.dataset.price_type
      });
      if(that.data.coll!=1){
        if(that.data.nav=='sear' || guanPage.data.one_id==that.data.one_class && guanPage.data.two_id==that.data.two_class){
          guanPage.setData({
            ["rightDatas[" + that.data.k_index + "].price_type"]:e.currentTarget.dataset.price_type,
            isguige:[]
          });
        };
      }else{
        app.globalData.shop_manage = 1;
      };      
    });
  },
  // 选择供应商
  chose_super:function(){
    util.showBuyModal(this);  
    var that = this;
    that.setData({
      issuper:true
    });
    if(that.data.good_dir_set<1){   //非企业版
      app.AppHttp('api/Client/SupplierList', {
        openid: app.globalData.openid,
        type: 1
      }, function (res) {
        console.log(JSON.stringify(res.data));
        if(res.data.status==-1){
          wx.showLoading({
            title: res.data.msg,
            duration:500
          });
          return;
        }
        var super_list=res.data.data[0]
        super_list = super_list.filter(function (item) {
          return (item.status==1 && item.is_zicai_supplier==0); //筛选正常且非自采的合作用户
        });
        that.setData({
          super_list:super_list
        });
      });
    }else if(that.data.good_dir_set>=1){  //企业版
      app.AppHttp('api/Client/belongBusinessSupplier', {
        client_id:app.globalData.loginInfo.id
      }, function (res) {
        console.log(JSON.stringify(res.data));
        if(res.data.status==-1){
          wx.showLoading({
            title: res.data.msg,
            duration:500
          });
          return;
        }
        that.setData({
          super_list: res.data
        });
      }); 
    }
  },
  // 关闭供应商弹窗
  close_super:function(){
    util.hideBuyModal(this,"issuper");
  },
  // 确定供应商
  super_conf:function(e){
    var that = this;
    var b_supplier_id=e.currentTarget.dataset.supplier_id;
    app.AppHttp('api/Supplier/setGoodBelongSupplier', {
      id:app.globalData.goodid,
      b_supplier_id:b_supplier_id
    }, function (res) {
      console.log(JSON.stringify(res.data));
      that.uplist();
      wx.showToast({
        title: res.data.msg
      });   
    })
    util.hideBuyModal(this,"issuper");
  },
  // 是否关联库存
  change_bank:function(){
    var that = this;
    var is_open=that.data.is_open;
    app.AppHttp('api/Goods/setIsOpen', {
      id: that.data.goodid,
      is_open:is_open
    }, function(res) {
      console.log(JSON.stringify(res.data));
      wx.showToast({
        title: '更新成功'
      });
      that.setData({
        is_open:is_open==0?1:0
      });
    });
  },
  // 点击所属分类弹窗
  fenleick: function() {
    util.showBuyModal(this);
    this.setData({
      showModalStatus: true
    })
    if (this.data.notwo == 1) {
      this.startcatelist();
    }
  },
  // 关闭所属分类弹窗
  closefenlei: function() {
    util.hideBuyModal(this,"showModalStatus");
  },
  // 确定并关闭所属分类弹窗
  fenleiconfirm: function() {
    var that = this;
    if (that.data.notwo == 1) {
      wx.showToast({
        title: '没有二级分类'
      })
      return;
    }; 
    util.hideBuyModal(that,"showModalStatus");
    that.setData({
      one_class_name: that.data.one_class_zhname,
      two_class_name: that.data.two_class_zhname,
      one_class: that.data.one_class_zh,
      two_class: that.data.two_class_zh
    });
    app.AppHttp('api/Goods/setGoodsClass', {
      id: that.data.goodid,
      one_class: that.data.one_class_zh,
      two_class: that.data.two_class_zh
    }, function(res) {
      console.log(JSON.stringify(res.data))
      wx.showToast({
        title: res.data.msg
      });
    }); 
  },
  // 选择所属分类
  bindChange: function(e) {
    var that = this;
    var val = e.detail.value;
    var one_class_list = this.data.one_class_list;
    var two_class_list = this.data.two_class_list;
    app.AppHttp('api/Supplier/CateList', {
      id: that.data.id,
      one_id: one_class_list[val[0]].private_one_class,
      e_type:'client'
    }, function(res) {
      // console.log(JSON.stringify(res.data));
      if (val[1] > res.data.two_class_list.length - 1) {
        val[1] = res.data.two_class_list.length - 1
      }
      if (res.data.two_class_list.length == 0) {
        that.setData({
          two_class_list: [''],
          notwo: 1
        })
        return;
      }
      that.setData({
        two_class_list: res.data.two_class_list,
        one_class_zhname: res.data.one_class_list[val[0]].private_class_name,
        two_class_zhname: res.data.two_class_list[val[1]].private_class_name,
        one_class_zh: res.data.one_class_list[val[0]].private_one_class,
        two_class_zh: res.data.two_class_list[val[1]].private_one_class,
        value: val,
        notwo: 0
      });
    })
  },
  // 查看历史价
  open_history:function(e){
    console.log(e.currentTarget.dataset);
    var win_unit_name=e.currentTarget.dataset.win_unit_name;
    var win_specs=e.currentTarget.dataset.win_specs;
    var win_goodlist=e.currentTarget.dataset.win_goodlist;
    console.log(win_goodlist)
    util.showBuyModal(this);
    this.setData({
      ishisprice:true,
      win_unit_name:win_unit_name,
      win_specs:win_specs,
      win_goodlist:win_goodlist
    });
  },
  // 关闭历史价
  close_his:function(){
    util.hideBuyModal(this,'ishisprice');
  },
  // 设置基础价
  setcost:function(e){
    this.setData({
      iscost:true,
      cost_id:e.currentTarget.dataset.id,
      z_cost_price:e.currentTarget.dataset.z_cost_price,
      cost_price:''
    });
  },
  // 关闭基础价
  cancel_cost:function(){
    this.setData({
      iscost:false
    });
  },
  // 输入基础价
  cost_input:function(e){
    var cost_price;
    if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) { //正则验证，提现金额小数点后不能大于2位数字
      cost_price = e.detail.value;
    } else {
      cost_price = e.detail.value.substring(0, e.detail.value.length - 1);
    };
    this.setData({
      cost_price: cost_price[0]=='.'?'0'+cost_price:cost_price
    });
  },
  // 保存基础价
  cost_conf:function(){
    var that = this;
    var cost_price=(that.data.cost_price*1).toFixed(2);
    app.AppHttp('api/Goods/setTruePrice', {
      id: that.data.cost_id,
      true_price:cost_price
    }, function(res) {
      console.log(JSON.stringify(res.data));
      that.setData({
        iscost:false
      });
      if(that.data.coll!=1){
        if(that.data.nav=='sear' || guanPage.data.one_id==that.data.one_class && guanPage.data.two_id==that.data.two_class){
          guanPage.setData({
            isguige:[],
            ["rightDatas[" + that.data.k_index + "].true_price"]:cost_price
          });
        };
      }else{
        app.globalData.shop_manage = 1;
      };     
      that.uplist();
    });    
  },
  // 设置等级
  setlevel:function(e){
    this.setData({
      islevel:true,
      level_id:e.currentTarget.dataset.level_id,
      cost_id:e.currentTarget.dataset.id,
      z_level_num:e.currentTarget.dataset.z_level_num,
      level_num:''
    });
  },
  // 关闭等级
  cancel_level:function(){
    this.setData({
      islevel:false
    });
  },
  // 输入级别价
  level_input:function(e){
    this.setData({
      level_num:e.detail.value
    });
  },
  // 保存等级
  level_conf:function(){
    var that = this;
    app.AppHttp('api/Goods/setLevelNum', {
      level_id: that.data.level_id,
      good_id:that.data.cost_id,
      supplier_id:app.globalData.loginInfo.id,
      level_num:that.data.level_num
    }, function(res) {
      console.log(JSON.stringify(res.data));
      that.setData({
        islevel:false
      });
      if(that.data.coll!=1){
        if(that.data.nav=='sear' || guanPage.data.one_id==that.data.one_class && guanPage.data.two_id==that.data.two_class){
          guanPage.setData({
            isguige:[]
          });
        };
      }else{
        app.globalData.shop_manage = 1;
      };     
      that.uplist();
    });
  },
  // 增加规格弹窗
  addguige: function() {
    this.setData({
      s_id: 0,
      guigetitle: "添加产品规格",
      selectguige: true,
      specs: "",
      specsdingjia: this.data.price_type == 1 ? '时价' : '固定价',
      specstrue_price: "",
      specsunit: "",
      specsunitindex: "",
      specsprice_type: this.data.price_type
    })
  },
  //输入规格详情
  specs_main_input:function(e){
    this.setData({
      specs_detail: e.detail.value
    })
  },
  // 输入规格名称
  specsinput: function(e) {
    this.setData({
      specs: e.detail.value
    })
  },
  // 关闭规格弹窗
  addguigecancel: function() {
    this.setData({
      selectshop:false,
      selectguige: false
    })
  },
  // 编辑产品弹窗
  editshop:function(){
    this.setData({
      guigetitle: "编辑产品规格",
      selectguige:false,
      selectshop:true,
      specs_unit_name:this.data.unit_name
    })
  },
  //编辑规格弹窗
  editguige: function(e) {
    console.log(e.currentTarget.dataset.id);
    this.setData({
      s_id: e.currentTarget.dataset.id.id,
      guigetitle: "编辑产品规格",
      selectguige: true,
      selectshop:false,
      specs: e.currentTarget.dataset.id.specs,
      specsdingjia: e.currentTarget.dataset.id.price_type == 1 ? '时价' : '固定价',
      specstrue_price: e.currentTarget.dataset.id.true_price,
      specsunit: e.currentTarget.dataset.id.unit_name,
      specsunitindex: e.currentTarget.dataset.id.unit,
      specsprice_type: e.currentTarget.dataset.id.price_type
    })
  },
  // 选择单位弹窗
  setDanWei: function(e) {
    var that = this;
    util.showBuyModal(this);
    that.setData({
      selectdanwei: true
    });
    app.AppHttp('api/Supplier/unit_list', {}, function(res) {
      // console.log(JSON.stringify(res.data))
      that.setData({
        unit_list: res.data
      })
    })
    that.setData({
      cal: e.currentTarget.dataset.cal
    })
  },
  // 添加单位
  addunit: function(e) {
    util.hideBuyModal(this,'selectdanwei');
    if (this.data.cal == 1) {
      this.setData({
        specsunit: e.target.dataset.unitname,
        specsunitindex: e.target.dataset.index
      })
    } else if (this.data.cal == 0) {
      this.setData({
        specs_unit_name: e.target.dataset.unitname,
        unitindex: e.target.dataset.index
      })
    }
  },
  // 关闭单位弹窗
  closedanwei: function() {
    util.hideBuyModal(this,'selectdanwei');
  },
  // 确定并关闭规格弹窗
  addguigeconfirm: function() {
    var that = this;
    console.log(that.data.specsunit);
    console.log(that.data.specsprice_type);
    console.log(that.data.specstrue_price);
    if (that.data.specsunit == '') {
      wx.showToast({
        title: '请选择单位'
      })
    } else {
      app.AppHttp('api/Supplier/AjaxAddSpecs', {
        id: that.data.goodid,   
        s_id: that.data.s_id,
        specs: that.data.specs,
        price_type: that.data.specsprice_type,
        true_price: that.data.specstrue_price!=''?that.data.specstrue_price:0,
        unit: that.data.specsunitindex,
        e_type:'client'
      }, function(res) {
        wx.showToast({
          title: res.data.msg
        })
        that.setData({
          selectguige: false
        });
        if(that.data.coll!=1){
          if(that.data.nav=='sear' || guanPage.data.one_id==that.data.one_class && guanPage.data.two_id==that.data.two_class){
            guanPage.setData({
              isguige:[],
              ["rightDatas[" + that.data.k_index + "].specs_count"]:that.data.s_id==0?that.data.specs_list.length+1:that.data.specs_list.length
            });
          };
        }else{
          app.globalData.shop_manage = 1;
        };   
        that.specsuplist();
      })
    }
  },
  // 删除规格并关闭规格弹窗
  delguigecancel: function(e) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定删除该规格？',
      success: function(sm) {
        if (sm.confirm) {
          // 用户点击了确定 可以调用删除方法了
          app.AppHttp('api/Supplier/AjaxDelSpecs', {
            id: e.currentTarget.dataset.s_id,
            good_id: that.data.goodid
          }, function(res) {
            wx.showToast({
              title: res.data.msg
            })
            that.setData({
              selectguige: false
            });
            if(that.data.coll!=1){
              if(that.data.nav=='sear' || guanPage.data.one_id==that.data.one_class && guanPage.data.two_id==that.data.two_class){
                guanPage.setData({
                  isguige:[],
                  ["rightDatas[" + that.data.k_index + "].specs_count"]:that.data.specs_list.length-1
                });
              };
            }else{
              app.globalData.shop_manage = 1;
            };  
            that.specsuplist();
          })
        }
      }
    })    
  },
  // 更新规格的列表展示
  specsuplist: function() {
    var that = this;
    app.AppHttp('api/Supplier/editGoodPage', {
      id: app.globalData.goodid
    }, function(res) {
      console.log(JSON.stringify(res.data));
      that.setData({
        specs_list: res.data.specs_list
      })
    });
  },
  /**
   * 删除产品
   */
  deleteClick: function() {
    let that = this;
    wx.showModal({
      title: '提示',
      content: '确定删除该产品 ？',
      success: function(sm) {
        if (sm.confirm) {
          if (that.data.specs_list.length == 0) {
            app.AppHttp('api/Supplier/deleteGood', {
              id: that.data.goodid
            }, function(res) {
              console.log(JSON.stringify(res.data))
              if (res.data.status == 1) {
                wx.showToast({
                  title: res.data.msg,
                  success: function() {
                    if(that.data.coll!=1){
                      del_ck=true;
                      if(that.data.k_index>=cur_page_index){   //商品在当前页
                        rightDatas.splice([cur_page_index],end);   //删除当前页的数据                     
                        guanPage.upshoplist();  //重新加载当前页的数据                            
                      }else{    //不在当前页
                        rightDatas.splice([that.data.k_index],1);
                        guanPage.setData({
                          rightDatas:rightDatas
                        });
                      };
                    }else{
                      app.globalData.shop_manage = 1;
                    };      
                    wx.navigateBack({
                      delta: 1
                    })
                  }
                })              
              }
            })
          } else {
            wx.showLoading({
              title: '请先删除规格',
              duration: 500
            });
          }
        } else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  // 打开上-下架弹窗
  open_status:function(){
    this.setData({
      isjia:true
    });
  },
  // 关闭上架-下架弹窗
  status_cancel:function(){
    this.setData({
      isjia:false
    });
  },
  // 确定上-下架
  status_conf:function(){
    var that = this;
    app.AppHttp('api/Supplier/LowerShelf', {
      ids:[that.data.goodid],
      status: that.data.status
    }, function (res) {
      // console.log(JSON.stringify(res.data))
      if (res.data.status) {
        wx.showToast({
          title: res.data.msg
        });
        if(that.data.coll!=1){
          if(that.data.nav=='sear' || guanPage.data.one_id==that.data.one_class && guanPage.data.two_id==that.data.two_class){
            guanPage.setData({
              ["rightDatas[" + that.data.k_index + "].status"]:that.data.status==1?0:1
            });
          };
        }else{
          app.globalData.shop_manage = 1;
        };
        that.setData({
          isjia:false,
          status:that.data.status==1?0:1
        });
      }
      console.log(JSON.stringify(res.data));
    })  
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    that.setData({
      id:app.globalData.loginInfo.id,
      goodid: app.globalData.goodid
    });
    if (app.globalData.imgSrc3 != '') {
      that.setData({
        imgSrc3: app.globalData.imgSrc3
      });
      console.log(app.globalData.imgSrc3)
      wx.uploadFile({
        url: app.globalData.url + 'api/Supplier/uploadGoodCover',
        filePath: that.data.imgSrc3,
        name: 'cover',
        method: "POST",
        success: function(res) {
          var obj = JSON.parse(res.data)
          console.log(obj.data)
          that.setData({
            setcover: obj.data
          });
          that.baochu();
          app.globalData.imgSrc3 = ''
        },
        fail: function(res) {
          wx.showModal({
            title: '错误提示',
            content: '上传图片失败',
            showCancel: false,
          })
          app.globalData.imgSrc3 = ''
        }
      });
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    var that = this;
    if(that.data.coll!=1 && del_ck==false && that.data.nav!='sear'){
      if(guanPage.data.one_id!=that.data.one_class || guanPage.data.two_id!=that.data.two_class){ //与原分类不同
        if(that.data.k_index>=cur_page_index){   //商品在当前页
          rightDatas.splice([cur_page_index],end);   //删除当前页的数据
          guanPage.upshoplist();  //重新加载当前页的数据
        }else{    //不在当前页
          rightDatas.splice([that.data.k_index],1);
          guanPage.setData({
            rightDatas:rightDatas
          });
        };
      };
    };
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})